package at.codebase.web.util.i10n;

import static at.codebase.web.util.i18n.I18NFactory.i18n;

import java.text.SimpleDateFormat;
import java.util.Date;

import at.codebase.web.util.i18n.I18NLocale;

/**
 * 
 * @author Lukas Pfeifhofer <lukas.pfeifhofer@devlabs.pro>
 *
 */
public class L10N {

	
	/**
	 * Formats the given timestamp in a local Date-String.
	 * 
	 * @param locale
	 * @param timestamp
	 * @return
	 */
	public static String formatDate(I18NLocale locale, long timestamp) {
		SimpleDateFormat sdf = new SimpleDateFormat(i18n(locale).string("timeDateFormat"));
		return sdf.format(new Date(timestamp));
	}
	
	/**
	 * Formats the given timestamp in a local Time-String.
	 * 
	 * @param locale
	 * @param timestamp
	 * @return
	 */
	public static String formatTime(I18NLocale locale, long timestamp) {
		SimpleDateFormat sdf = new SimpleDateFormat(i18n(locale).string("timeTimeFormat"));
		return sdf.format(new Date(timestamp));
	}
	
	public static String formatTimeExact(I18NLocale locale, long timestamp) {
		SimpleDateFormat sdf = new SimpleDateFormat(i18n(locale).string("timeTimeExactFormat"));
		return sdf.format(new Date(timestamp));
	}
	
	/**
	 * Formats the given amount in a local Money-String.
	 * 
	 * @param locale
	 * @param timestamp(in Secounds)
	 * @return
	 */
	public static String formatMoney(I18NLocale locale, double amount) {
		return String.format("%(,.2f", new Double(amount));
	}

}
